﻿using System;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SwinGame;

namespace SimpleSurvival.src
{
    //-----------------------------------------------//
    //CLASS - CameraController.cs
    //-----------------------------------------------//
    //Controls the camera
    //Kinda obsolete since there's only one camera
    public class CameraController : ObjectController<ICamera>
    {
        //boundary size on the screens edges that the mouse will
        //touch to move the screen in the respective direction
        //rts style
        const int SCREEN_MOVE_ZONE_SIZE = 45;

        public CameraController(ICamera c) { LinkToObject(c); }

        public override void GetInput(double dt)
        {
            //Get keyboard input
            Point kbOffset = KeyboardInput.GetKeyboardOffset(KeyCode.vk_LEFT,
                KeyCode.vk_RIGHT,KeyCode.vk_UP, KeyCode.vk_DOWN);

            //Move the camera in keys pressed
            ControlledObject.MoveCamera(kbOffset.X, kbOffset.Y, dt);

            //Reset camera if space pressed
            if (Input.KeyDown(KeyCode.vk_SPACE)) { ControlledObject.ResetCameraPos(); }

            //Set rectangles for screen edges
            System.Drawing.Rectangle lRect = new System.Drawing.Rectangle(
                0, 0, SCREEN_MOVE_ZONE_SIZE, GameMain.SCREEN_HEIGHT);

            System.Drawing.Rectangle rRect = new System.Drawing.Rectangle(
                GameMain.SCREEN_WIDTH - SCREEN_MOVE_ZONE_SIZE, 0, 
                SCREEN_MOVE_ZONE_SIZE, GameMain.SCREEN_HEIGHT);

            System.Drawing.Rectangle tRect = new System.Drawing.Rectangle(
                0, 0, GameMain.SCREEN_WIDTH, SCREEN_MOVE_ZONE_SIZE);

            System.Drawing.Rectangle bRect = new System.Drawing.Rectangle(
                0, GameMain.SCREEN_HEIGHT - SCREEN_MOVE_ZONE_SIZE,
                GameMain.SCREEN_WIDTH, SCREEN_MOVE_ZONE_SIZE);

            //Check for mouse in rects and move if neccessary
            Vector v = Input.MousePositionAsVector();

            if (lRect.Contains(new Point((int)v.X, (int)v.Y)))
            {
                ControlledObject.MoveCamera(-1, 0, dt);
            }
            else if (rRect.Contains(new Point((int)v.X, (int)v.Y)))
            {
                ControlledObject.MoveCamera(1, 0, dt);
            }

            if (tRect.Contains(new Point((int)v.X, (int)v.Y)))
            {
                ControlledObject.MoveCamera(0, -1, dt);
            }
            else if (bRect.Contains(new Point((int)v.X, (int)v.Y)))
            {
                ControlledObject.MoveCamera(0, 1, dt);
            }

        }
    }
}
